package com.indexingsystem.system.task;

import java.io.File;
import java.io.FileInputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;

import com.indexingsystem.boss.Vo.ExportInstitutionListByIdVo;
import com.indexingsystem.boss.common.ImportClientHttpUtil;
import com.indexingsystem.boss.entity.AnalysisList;
import com.indexingsystem.boss.entity.AppInstitutionRelations;
import com.indexingsystem.boss.entity.Applications;
import com.indexingsystem.boss.entity.ArticleContents;
import com.indexingsystem.boss.entity.Articles;
import com.indexingsystem.boss.entity.AuditLogs;
import com.indexingsystem.boss.entity.Books;
import com.indexingsystem.boss.entity.Contract;
import com.indexingsystem.boss.entity.Games;
import com.indexingsystem.boss.entity.Institutions;
import com.indexingsystem.boss.entity.Invoices;
import com.indexingsystem.boss.entity.Iprules;
import com.indexingsystem.boss.entity.Magazines;
import com.indexingsystem.boss.entity.OftenConsignees;
import com.indexingsystem.boss.entity.OrderProcesses;
import com.indexingsystem.boss.entity.OrderProducts;
import com.indexingsystem.boss.entity.OrderResourceProductsDetail;
import com.indexingsystem.boss.entity.OrderResoursePrice;
import com.indexingsystem.boss.entity.Orders;
import com.indexingsystem.boss.entity.Pusers;
import com.indexingsystem.boss.entity.ResCategoryRelations;
import com.indexingsystem.boss.entity.ResourceCategors;
import com.indexingsystem.boss.entity.ResourceRelations;
import com.indexingsystem.boss.entity.ResourceType;
import com.indexingsystem.boss.entity.Resources;
import com.indexingsystem.boss.entity.RoleGroups;
import com.indexingsystem.boss.entity.Roles;
import com.indexingsystem.boss.entity.SpecialResourceDatas;
import com.indexingsystem.boss.entity.Terminals;
import com.indexingsystem.boss.entity.UserInfos;
import com.indexingsystem.boss.entity.UserInstitution;
import com.indexingsystem.boss.entity.UserRole;
import com.indexingsystem.boss.entity.Videos;
import com.indexingsystem.boss.logback.LogCvt;
import com.indexingsystem.boss.utils.CreateFileUtil;
import com.indexingsystem.boss.utils.DateUtil;
import com.indexingsystem.boss.utils.JsonUtils;

public class ExportInstitutionList {

	public static String exportInstitutions(ExportInstitutionListByIdVo exportInstitutionListByIdVo,String institutionId){
		StringBuffer sb = new StringBuffer();
		//1、机构信息离线数据包:全量升级
		List<Institutions> institutionsList = exportInstitutionListByIdVo.getInstitutionsList();
		sb.append("-- ----------------------------------------- \n");
		sb.append("-- dh_institutions ------------------------- \n");
		sb.append("-- ----------------------------------------- \n");
	    sb.append("DROP TABLE IF EXISTS `dh_institutions`;");
	    sb.append("\n");
	    sb.append("CREATE TABLE `dh_institutions` (");
	    sb.append("\n");
	    sb.append(" `institution_id` varchar(32) NOT NULL," + "\n"
			+ " `parent_id` varchar(32) DEFAULT '0'," + "\n"
			+ " `institution_order` varchar(50) DEFAULT NULL," + "\n"
			+ " `institution_name` varchar(256) DEFAULT NULL," + "\n"
			+ " `institution_display_name` varchar(256) DEFAULT NULL," + "\n"
			+ " `institution_type` int(11) DEFAULT '0'," + "\n"
			+ " `nature` varchar(256) DEFAULT NULL," + "\n"
			+ " `industry` varchar(255) DEFAULT NULL," + "\n"
			+ " `province` varchar(256) DEFAULT NULL," + "\n"
			+ " `city` varchar(256) DEFAULT NULL," + "\n"
			+ " `address` varchar(256) DEFAULT NULL," + "\n"
			+ " `phone` varchar(256) DEFAULT NULL," + "\n"
			+ " `contact_name` varchar(256) DEFAULT NULL," + "\n"
			+ " `postcode` varchar(256) DEFAULT NULL,"+ "\n"
			+ " `description` varchar(256) DEFAULT NULL,"+ "\n"
			+ " `enabled` int(11) DEFAULT '0',"+ "\n"
			+ " `valid_date` varchar(20) DEFAULT NULL,"+ "\n"
			+ " `create_date` datetime DEFAULT NULL,"+ "\n"
			+ " `create_user_id` varchar(32) DEFAULT NULL,"+ "\n"
			+ " `last_updated_date` datetime DEFAULT NULL,"+ "\n"
			+ " `last_updated_user_id` varchar(32) DEFAULT NULL,"+ "\n"
			+ " `jg_server_type` int(11) DEFAULT NULL,"+ "\n"
			+ " `update_status` int(11) DEFAULT NULL ,"+ "\n"
			+ " PRIMARY KEY (`institution_id`)");
	    sb.append("\n");
	    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    sb.append("\n \n");
	    //update
	    if (null != institutionsList && institutionsList.size() > 0) {
		    for (int i = 0; i < institutionsList.size(); i++) {
	    	    Institutions institutions = institutionsList.get(i);
	    	    sb.append("INSERT INTO `dh_institutions` VALUES (");
	    	    sb.append(
	    	 	"'"+stringIsNull(institutions.getInstitutionId())+"'"+
	    	    ", '"+stringIsNull(institutions.getParentId())+"'"+
	    	    ", '"+stringIsNull(institutions.getInstitutionOrder())+"'"+
	    	    ", '"+stringIsNull(institutions.getInstitutionName())+"'"+
			 	", '"+stringIsNull(institutions.getInstitutionDisplayName())+"'"+
			 	", "+institutions.getInstitutionType()+
			 	", '"+stringIsNull(institutions.getNature())+"'"+
			 	", '"+stringIsNull(institutions.getIndustry())+"'"+
			 	", '"+stringIsNull(institutions.getProvince())+"'"+
			 	", '"+stringIsNull(institutions.getCity())+"'"+
			 	", '"+stringIsNull(institutions.getAddress())+"'"+
			 	", '"+stringIsNull(institutions.getPhone())+"'"+
			 	", '"+stringIsNull(institutions.getContactName())+"'"+
			 	", '"+stringIsNull(institutions.getPostcode())+"'"+
			 	", '"+stringIsNull(institutions.getDescription())+"'"+
			 	", "+institutions.getEnabled()+
			 	", '"+stringIsNull(institutions.getValidDate())+"'"+
			 	", "+dateIsNull(DateUtil.formatToString(institutions.getCreateDate()))+
			 	", '"+stringIsNull(institutions.getCreateUserId())+"'"+
			 	", "+dateIsNull(DateUtil.formatToString(institutions.getLastUpdatedDate()))+
			 	", '"+stringIsNull(institutions.getLastUpdatedUserId())+"'"+
			 	", "+institutions.getJgServerType()+
			 	", "+institutions.getUpdateStatus()+");");
	    	    sb.append("\n");
	        }
	    }
	    sb.append("\n \n");
	    
	    //2、机构用户离线数据包：增量升级
	    sb.append("-- ----------------------------------------- \n");
	    sb.append("-- dh_users -------------------------------- \n");
	    sb.append("-- ----------------------------------------- \n");
	    List<Pusers> pusersList = exportInstitutionListByIdVo.getPusersList();
	    if (null != pusersList && pusersList.size() > 0) {
	    	for (int i = 0; i < pusersList.size(); i++) {
		    	Pusers pusers = pusersList.get(i);
		    	sb.append("INSERT INTO `dh_users`("
		    			+ "`user_id`,`user_name`,`display_name`,`password`,`email`,"
		    			+ "`user_folder`,`portrait`,`create_date`,`status`,`is_activate`,"
		    			+ "`is_autonym`,`is_super`,`update_password_date`,"
		    			+ "`register_source`,`activate_key`,`activate_last_date`,`last_login_date`,`locked`,`salt`)");
		    	sb.append("SELECT ");
		    	sb.append(
			    		"'"+stringIsNull(pusers.getUserId())+"'"+
	    				", '"+stringIsNull(pusers.getUserName())+"'"+
	    	    	    ", '"+stringIsNull(pusers.getDisplayName()+"'"+
	    	    	    ", '"+stringIsNull(pusers.getPassword())+"'"+
	    			 	", '"+stringIsNull(pusers.getEmail())+"'"+
	    			 	", '"+stringIsNull(pusers.getUserFolder())+"'"+
	    			 	", '"+stringIsNull(pusers.getPortrait())+"'"+
	    			 	", "+dateIsNull(DateUtil.formatToString(pusers.getCreateDate()))+
	    			 	", "+pusers.getStatus()+
	    			 	", "+pusers.getIsActivate()+
	    			 	", "+pusers.getIsAutonym()+
	    			 	", "+pusers.getIsSuper()+
						", "+dateIsNull(DateUtil.formatToString(pusers.getUpdatePasswordDate()))+
						", '"+stringIsNull(pusers.getRegisterSource())+"'"+
						", '"+stringIsNull(pusers.getActivateKey())+"'"+
						", '"+stringIsNull(pusers.getActivateLastDate())+"'"+
						", "+dateIsNull(DateUtil.formatToString(pusers.getLastLoginDate()))+
						", "+pusers.getLocked())+  			 	
						", '"+stringIsNull(pusers.getSalt())+"'");
		    	sb.append(" FROM DUAL WHERE NOT EXISTS(");
		    	sb.append("SELECT `user_id` FROM `dh_users` WHERE `user_id` = "+"'"+pusers.getUserId()+"');\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    //3、获取用户详情信息:增量升级
	    sb.append("-- ----------------------------------------- \n");
	    sb.append("-- dh_user_infos --------------------------- \n");
	    sb.append("-- ----------------------------------------- \n");
	    List<UserInfos> userInfosList = exportInstitutionListByIdVo.getUserInfosList();
	    if (null != userInfosList && userInfosList.size() > 0) {
	    	for (int i = 0; i < userInfosList.size(); i++) {
		    	UserInfos userInfos = userInfosList.get(i);
		    	sb.append("INSERT INTO `dh_user_infos`("
		    			+ "`user_info_id`,`user_id`,`real_name`,`first_name`,`last_name`,"
		    			+ "`identity_card`,`phone`,`mobile`,`sex`,`birthday`,"
		    			+ "`province`,`city`,`address`,`qq`,"
		    			+ "`post_code`,`credit`,`school`,`last_login_ip`)");
		    	sb.append("SELECT ");
		    	sb.append(
			    		"'"+stringIsNull(userInfos.getUserInfoId())+"'"+
	    				", '"+stringIsNull(userInfos.getUserId())+"'"+
	    	    	    ", '"+stringIsNull(userInfos.getRealName())+"'"+
	    	    	    ", '"+stringIsNull(userInfos.getFirstName())+"'"+
	    			 	", '"+stringIsNull(userInfos.getLastName())+"'"+
	    			 	", '"+stringIsNull(userInfos.getIdentityCard())+"'"+
	    			 	", '"+stringIsNull(userInfos.getPhone())+"'"+
	    			 	", '"+stringIsNull(userInfos.getMobile())+"'"+
	    			 	", "+userInfos.getSex()+
	    			 	", "+dateIsNull(DateUtil.formatToString(userInfos.getBirthday()))+
	    			 	", '"+stringIsNull(userInfos.getProvince())+"'"+
	    			 	", '"+stringIsNull(userInfos.getCity())+"'"+
						", '"+stringIsNull(userInfos.getAddress())+"'"+
						", '"+stringIsNull(userInfos.getQq())+"'"+
						", '"+stringIsNull(userInfos.getPostCode())+"'"+
						", "+userInfos.getCredit()+
						", '"+stringIsNull(userInfos.getSchool())+"'"+
						", '"+stringIsNull(userInfos.getLastLoginIp())+"'");    			 	
		    	sb.append(" FROM DUAL WHERE NOT EXISTS(");
		    	sb.append("SELECT `user_info_id` FROM `dh_user_infos` WHERE `user_info_id` = "+"'"+userInfos.getUserInfoId()+"');\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    //4、获取用户机构关系信息数据包：增量升级
	    sb.append("-- ----------------------------------------- \n");
	    sb.append("-- dh_user_institution --------------------- \n");
	    sb.append("-- ----------------------------------------- \n");
	    List<UserInstitution> userInstitutionList = exportInstitutionListByIdVo.getUserInstitutionList();
	    if (null != userInstitutionList && userInstitutionList.size() > 0) {
	    	for (int i = 0; i < userInstitutionList.size(); i++) {
				UserInstitution userInstitution = userInstitutionList.get(i);
				sb.append("INSERT INTO `dh_user_institution`("
		    			+ "`user_institution_id`,`institution_id`,`user_id`,`relation`)");
		    	sb.append("SELECT ");
		    	sb.append(
			    		"'"+stringIsNull(userInstitution.getUserInstitutionId())+"'"+
	    				", '"+stringIsNull(userInstitution.getInstitutionId())+"'"+
	    	    	    ", '"+stringIsNull(userInstitution.getUserId())+"'"+
	    	    	    ", "+userInstitution.getRelation());    			 	
		    	sb.append(" FROM DUAL WHERE NOT EXISTS(");
		    	sb.append("SELECT `user_institution_id` FROM `dh_user_institution` WHERE `user_institution_id` = "+"'"+userInstitution.getUserInstitutionId()+"');\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    //5、获取用户角色关系信息数据包：增量升级
	    sb.append("-- ----------------------------------------- \n");
	    sb.append("-- dh_user_role ---------------------------- \n");
	    sb.append("-- ----------------------------------------- \n");
	    List<UserRole> userRolesList = exportInstitutionListByIdVo.getUserRoleList();
	    if (null != userRolesList && userRolesList.size() > 0) {
			for (int i = 0; i < userRolesList.size(); i++) {
				UserRole userRole = userRolesList.get(i);
				sb.append("INSERT INTO `dh_user_role`("
		    			+ "`user_role_id`,`user_id`,`user_name`,`role_id`)");
		    	sb.append("SELECT ");
		    	sb.append(
			    		"'"+stringIsNull(userRole.getUserRoleId())+"'"+
	    				", '"+stringIsNull(userRole.getUserId())+"'"+
	    	    	    ", '"+stringIsNull(userRole.getUserName())+"'"+
	    	    	    ", '"+stringIsNull(userRole.getRoleId())+"'");    			 	
		    	sb.append(" FROM DUAL WHERE NOT EXISTS(");
		    	sb.append("SELECT `user_role_id` FROM `dh_user_role` WHERE `user_role_id` = "+"'"+userRole.getUserRoleId()+"');\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    //6、获取角色关系信息数据包：增量升级
	    sb.append("-- ----------------------------------------- \n");
	    sb.append("-- dh_roles -------------------------------- \n");
	    sb.append("-- ----------------------------------------- \n");
	    List<Roles> rolesList = exportInstitutionListByIdVo.getRolesList();
	    if (null != rolesList && rolesList.size() > 0) {
			for (int i = 0; i < rolesList.size(); i++) {
				Roles roles = rolesList.get(i);
				sb.append("INSERT INTO `dh_roles`("
		    			+ "`role_id`,`role_code`,`role_name`,`parent_role_id`,`institution_order`,"
		    			+ "`role_group_id`,`auto_assignment`,`description`,`create_date`,`create_user_id`,"
		    			+ "`last_updated_date`,`last_updated_user_id`)");
		    	sb.append("SELECT ");
		    	sb.append(
			    		"'"+stringIsNull(roles.getRoleId())+"'"+
	    				", '"+stringIsNull(roles.getRoleCode())+"'"+
	    	    	    ", '"+stringIsNull(roles.getRoleName())+"'"+
	    	    	    ", '"+stringIsNull(roles.getParentRoleId())+"'"+
	    			 	", '"+stringIsNull(roles.getInstitutionOrder())+"'"+
	    			 	", '"+stringIsNull(roles.getRoleGroupId())+"'"+
	    			 	", "+roles.getAutoAssignment()+
	    			 	", '"+stringIsNull(roles.getDescription())+"'"+
	    			 	", "+dateIsNull(DateUtil.formatToString(roles.getCreateDate()))+
	    			 	", '"+stringIsNull(roles.getCreateUserId())+"'"+
	    			 	", "+dateIsNull(DateUtil.formatToString(roles.getLastUpdatedDate()))+
	    			 	", '"+stringIsNull(roles.getLastUpdatedUserId())+"'");
		    	sb.append(" FROM DUAL WHERE NOT EXISTS(");
		    	sb.append("SELECT `role_id` FROM `dh_roles` WHERE `role_id` = "+"'"+roles.getRoleId()+"');\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    sb.append("-- ----------------------------------------- \n");
	    sb.append("-- dh_role_groups -------------------------- \n");
	    sb.append("-- ----------------------------------------- \n");
	    //7、获取角色组信息数据包：增量升级
	    List<RoleGroups> roleGroupsList = exportInstitutionListByIdVo.getRoleGroupsList();
	    if (null != roleGroupsList && roleGroupsList.size() > 0) {
	    	for (int i = 0; i < roleGroupsList.size(); i++) {
	    		RoleGroups roleGroups = roleGroupsList.get(i);
	    		sb.append("INSERT INTO `dh_role_groups`("
		    			+ "`role_group_id`,`role_group_name`,`description`,`create_date`,`create_user_id`,"
		    			+ "`last_updated_date`,`last_updated_user_id`)");
		    	sb.append("SELECT ");
		    	sb.append(
			    		"'"+stringIsNull(roleGroups.getRoleGroupId())+"'"+
	    				", '"+stringIsNull(roleGroups.getRoleGroupName())+"'"+
	    	    	    ", '"+stringIsNull(roleGroups.getDescription())+"'"+
	    	    	    ", "+dateIsNull(DateUtil.formatToString(roleGroups.getCreateDate()))+
	    			 	", '"+stringIsNull(roleGroups.getCreateUserId())+"'"+
	    			 	", "+dateIsNull(DateUtil.formatToString(roleGroups.getLastUpdatedDate()))+
	    			 	", '"+stringIsNull(roleGroups.getLastUpdatedUserId())+"'");
		    	sb.append(" FROM DUAL WHERE NOT EXISTS(");
		    	sb.append("SELECT `role_group_id` FROM `dh_role_groups` WHERE `role_group_id` = "+"'"+roleGroups.getRoleGroupId()+"');\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    sb.append("-- ----------------------------------------- \n");
	    sb.append("-- dh_terminals ---------------------------- \n");
	    sb.append("-- ----------------------------------------- \n");
	    //8、获取终端列表离线数据包：全量升级
	    List<Terminals> terminalsList = exportInstitutionListByIdVo.getTerminalsList();
	    sb.append("DROP TABLE IF EXISTS `dh_terminals`;");
	    sb.append("\n");
	    
	    sb.append("CREATE TABLE `dh_terminals` (");
	    sb.append("\n");
	    sb.append(" `terminal_id` varchar(32) NOT NULL," + "\n"
			+ " `terminal_code` varchar(32) NOT NULL," + "\n"
			+ " `terminal_name` varchar(255) NOT NULL," + "\n"
			+ " `description` varchar(256) DEFAULT NULL," + "\n"
			+ " PRIMARY KEY (`terminal_id`)");
	    sb.append("\n");
	    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    sb.append("\n \n");
	    //update
	    if (null != terminalsList && terminalsList.size() > 0) {
			for (Terminals terminals : terminalsList) {
				sb.append("INSERT INTO `dh_terminals` VALUES (");
	    	    sb.append(
	    	 	"'"+stringIsNull(terminals.getTerminalId())+"'"+
	    	    ", '"+stringIsNull(terminals.getTerminalCode())+"'"+
	    	    ", '"+stringIsNull(terminals.getTerminalName())+"'"+
			 	", '"+stringIsNull(terminals.getDescription())+"');");
	    	    sb.append("\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    sb.append("-- ----------------------------------------- \n");
	    sb.append("-- dh_iprules ------------------------------ \n");
	    sb.append("-- ----------------------------------------- \n");
	    //9、获取IP规则离线数据包：全量升级
	    List<Iprules> iprulesList = exportInstitutionListByIdVo.getIprulesList();
	    sb.append("DROP TABLE IF EXISTS `dh_iprules`;");
	    sb.append("\n");
	    
	    sb.append("CREATE TABLE `dh_iprules` (");
	    sb.append("\n");
	    sb.append(" `ip_rule_id` varchar(32) NOT NULL," + "\n"
			+ " `institution_id` varchar(32) NOT NULL," + "\n"
			+ " `rule_name` varchar(255) NOT NULL," + "\n"
			+ " `sort_index` int(11) DEFAULT NULL," + "\n"
			+ " `rule_mode` int(11) DEFAULT NULL," + "\n"
			+ " `expression` varchar(1000) DEFAULT NULL," + "\n"
			+ " `enabled` int(11) DEFAULT NULL," + "\n"
			+ " `user_id` varchar(32) DEFAULT NULL," + "\n"
			+ " PRIMARY KEY (`ip_rule_id`)");
	    sb.append("\n");
	    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    sb.append("\n \n");
	    //update
	    if (null != iprulesList && iprulesList.size() > 0) {
			for (Iprules iprules : iprulesList) {
				sb.append("INSERT INTO `dh_iprules` VALUES (");
	    	    sb.append(
	    	 	"'"+stringIsNull(iprules.getIpRuleId())+"'"+
	    	    ", '"+stringIsNull(iprules.getInstitutionId())+"'"+
	    	    ", '"+stringIsNull(iprules.getRuleName())+"'"+
	    	    ", "+iprules.getSortIndex()+
	    	    ", "+iprules.getRuleMode()+
	    	    ", '"+stringIsNull(iprules.getExpression())+"'"+
	    	    ", "+iprules.getEnabled()+
			 	", '"+stringIsNull(iprules.getUserId())+"');");
	    	    sb.append("\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    
	    sb.append("-- ----------------------------------------- \n ");
	    sb.append("-- dh_appinstitution_relations ------------- \n ");
	    sb.append("-- ----------------------------------------- \n ");
	    //10、获取平台关系列表离线数据包？？？？：全量升级
	    List<AppInstitutionRelations> relaByInstitutionIdList = exportInstitutionListByIdVo.getRelaByInstitutionIdList();
	    sb.append("DROP TABLE IF EXISTS `dh_appinstitution_relations`;");
	    sb.append("\n");
	    sb.append("CREATE TABLE `dh_appinstitution_relations` (");
	    sb.append("\n");
	    sb.append(" `relations_id` varchar(32) NOT NULL," + "\n"
    		  + " `app_name` varchar(50) DEFAULT NULL," + "\n"
    		  + " `app_id` varchar(32) DEFAULT NULL," + "\n"
    		  + " `institution_id` varchar(32) DEFAULT NULL," + "\n"
    		  + " `institution_url` varchar(255) DEFAULT NULL," + "\n"
    		  + " `create_date` datetime DEFAULT NULL," + "\n"
    		  + " `parent_institution_id` varchar(32) DEFAULT NULL," + "\n"
			+ " PRIMARY KEY (`relations_id`)");
	    sb.append("\n");
	    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    sb.append("\n \n");
	    //update
	    if (null != relaByInstitutionIdList && relaByInstitutionIdList.size() > 0) {
			for (AppInstitutionRelations appInstitutionRelations : relaByInstitutionIdList) {
				sb.append("INSERT INTO `dh_appinstitution_relations` VALUES (");
	    	    sb.append(
	    	 	"'"+stringIsNull(appInstitutionRelations.getRelationsId())+"'"+
	    	    ", '"+stringIsNull(appInstitutionRelations.getAppName())+"'"+
	    	    ", '"+stringIsNull(appInstitutionRelations.getAppId())+"'"+
	    	    ", '"+stringIsNull(appInstitutionRelations.getInstitutionId())+"'"+
	    	    ", '"+stringIsNull(appInstitutionRelations.getInstitutionUrl())+"'"+
	    	    ", "+dateIsNull(DateUtil.formatToString(appInstitutionRelations.getCreateDate()))+
			 	", '"+stringIsNull(appInstitutionRelations.getParentInstitutionId())+"');");
	    	    sb.append("\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    sb.append("-- ----------------------------------------- \n ");
	    sb.append("-- dh_analysis_list ------------------------ \n ");
	    sb.append("-- ----------------------------------------- \n ");
	    //10、获取平台列表离线数据包？？？？：全量升级
	    AnalysisList analysisList = exportInstitutionListByIdVo.getAnalysisList();
	    sb.append("DROP TABLE IF EXISTS `dh_analysis_list`;");
	    sb.append("\n");
	    sb.append("CREATE TABLE `dh_analysis_list` (");
	    sb.append("\n");
	    sb.append(" `analysis_id` varchar(32) NOT NULL," + "\n"
			  + " `institution_id` varchar(32) NOT NULL," + "\n"
			  + " `resources_count` int(11) DEFAULT NULL," + "\n"
			  + " `orders_count` int(11) DEFAULT NULL," + "\n"
			  + " `user_count` int(11) DEFAULT NULL," + "\n"
			  + " `platform_count` int(11) DEFAULT NULL," + "\n"
			  + " `page_count` int(11) DEFAULT NULL," + "\n"
			  + " `prowse_count` int(11) DEFAULT NULL," + "\n"
			  + " `read_count` int(11) DEFAULT NULL," + "\n"
			  + " PRIMARY KEY (`analysis_id`)");
	    sb.append("\n");
	    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    sb.append("\n \n");
	    //update
	    if (null != analysisList) {
			sb.append("INSERT INTO `dh_analysis_list` VALUES (");
    	    sb.append(
    	 	"'"+stringIsNull(analysisList.getAnalysisId())+"'"+
    	    ", '"+stringIsNull(analysisList.getInstitutionId())+"'"+
    	    ", "+analysisList.getResourcesCount()+
    	    ", "+analysisList.getOrdersCount()+
    	    ", "+analysisList.getUserCount()+
    	    ", "+analysisList.getPlatformCount()+
    	    ", "+analysisList.getPageCount()+
    	    ", "+analysisList.getProwseCount()+
		 	", "+analysisList.getReadCount()+");");
    	    sb.append("\n");
		}
	    sb.append("\n \n \n");
	    
	    
	    sb.append("-- ----------------------------------------- \n");
	    sb.append("-- dh_applications ------------------------- \n");
	    sb.append("-- ----------------------------------------- \n");
	    //10、获取平台列表离线数据包？？？？：全量升级
	    List<Applications> applicationsList = exportInstitutionListByIdVo.getApplicationsList();
	    sb.append("DROP TABLE IF EXISTS `dh_applications`;");
	    sb.append("\n");
	    
	    sb.append("CREATE TABLE `dh_applications` (");
	    sb.append("\n");
	    sb.append(" `app_id` varchar(32) NOT NULL," + "\n"
    		  + " `app_name` varchar(256) DEFAULT NULL," + "\n"
    		  + " `app_key` varchar(256) DEFAULT NULL," + "\n"
    		  + " `app_secret` varchar(256) DEFAULT NULL," + "\n"
    		  + " `app_image` varchar(512) DEFAULT NULL," + "\n"
    		  + " `app_summary` text," + "\n"
    		  + " `app_uri` varchar(512) DEFAULT NULL," + "\n"
    		  + " `app_ip` varchar(15) DEFAULT NULL," + "\n"
    		  + " `scope` varchar(1024) DEFAULT NULL," + "\n"
    		  + " `app_type` int(11) DEFAULT NULL," + "\n"
    		  + " `auth_type` int(11) DEFAULT NULL," + "\n"
    		  + " `response_type` varchar(128) DEFAULT NULL," + "\n"
    		  + " `grant_type` varchar(128) DEFAULT NULL," + "\n"
    		  + " `status` int(11) DEFAULT NULL," + "\n"
    		  + " `create_date` datetime DEFAULT NULL," + "\n"
    		  + " `create_user_id` varchar(32) DEFAULT NULL," + "\n"
    		  + " `last_updated_date` datetime DEFAULT NULL," + "\n"
    		  + " `last_updated_user_id` varchar(32) DEFAULT NULL," + "\n"
			+ " PRIMARY KEY (`app_id`)");
	    sb.append("\n");
	    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    sb.append("\n \n");
	    //update
	    if (null != applicationsList && applicationsList.size() > 0) {
			for (Applications applications : applicationsList) {
				sb.append("INSERT INTO `dh_applications` VALUES (");
	    	    sb.append(
	    	 	"'"+stringIsNull(applications.getAppId())+"'"+
	    	    ", '"+stringIsNull(applications.getAppName())+"'"+
	    	    ", '"+stringIsNull(applications.getAppKey())+"'"+
	    	    ", '"+stringIsNull(applications.getAppSecret())+"'"+
	    	    ", '"+stringIsNull(applications.getAppImage())+"'"+
	    	    ", '"+stringIsNull(applications.getAppSummary())+"'"+
	    	    ", '"+stringIsNull(applications.getAppUri())+"'"+
	    	    ", '"+stringIsNull(applications.getAppIp())+"'"+
	    	    ", '"+stringIsNull(applications.getScope())+"'"+
	    	    ", "+applications.getAppType()+
	    	    ", "+applications.getAuthType()+
	    	    ", '"+stringIsNull(applications.getResponseType())+"'"+
	    	    ", '"+stringIsNull(applications.getGrantType())+"'"+
	    	    ", "+applications.getStatus()+
	    	    ", "+dateIsNull(DateUtil.formatToString(applications.getCreateDate()))+
	    	    ", '"+stringIsNull(applications.getCreateUserId())+"'"+
	    	    ", "+dateIsNull(DateUtil.formatToString(applications.getLastUpdatedDate()))+
			 	", '"+stringIsNull(applications.getLastUpdatedUserId())+"');");
	    	    sb.append("\n");
			}
		}
	    sb.append("\n \n \n");
	    
	    /* sb.append("-- ----------------------------------------- \n ");
	    sb.append("-- dh_order_products ----------------------- \n ");
	    sb.append("-- ----------------------------------------- \n ");
	    //11、获取资源类型离线数据包：全量升级
	    List<OrderProducts> orderProductsListList = exportInstitutionListByIdVo.getOrderProductsList();
	    sb.append("DROP TABLE IF EXISTS `dh_order_products`;");
	    sb.append("\n");
	    
	    sb.append("CREATE TABLE `dh_order_products` (");
	    sb.append("\n");
	    sb.append(" `order_product_id` varchar(32) NOT NULL," + "\n"
	    		  + " `order_id` varchar(32) NOT NULL," + "\n"
	    		  + " `product_id` varchar(32) NOT NULL," + "\n"
	    		  + " `product_name` varchar(100) NOT NULL," + "\n"
	    		  + " `alias` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `product_type` int(11) NOT NULL DEFAULT '0' COMMENT '0：资源分类  1:资源'," + "\n"
	    		  + " `order_type` int(11) NOT NULL DEFAULT '1'," + "\n"
	    		  + " `res_category_id` varchar(32) NOT NULL," + "\n"
	    		  + " `res_category_name` varchar(200) NOT NULL," + "\n"
	    		  + " `publishyear` varchar(4) DEFAULT NULL," + "\n"
	    		  + " `publishmonth` varchar(2) DEFAULT NULL," + "\n"
	    		  + " `institutions_id` varchar(32) NOT NULL," + "\n"
	    		  + " `up_institutions_id` varchar(32) NOT NULL," + "\n"
	    		  + " `product_abbreviation` varchar(10) DEFAULT NULL," + "\n"
	    		  + " `start_year` varchar(4) DEFAULT NULL," + "\n"
	    		  + " `end_year` varchar(4) DEFAULT NULL," + "\n"
	    		  + " `product_price` varchar(20) NOT NULL DEFAULT '0'," + "\n"
	    		  + " `reserve_end_date` varchar(10) DEFAULT NULL," + "\n"
	    		  + " `reserve_number` int(11) DEFAULT '0'," + "\n"
	    		  + " `create_time` varchar(20) NOT NULL," + "\n"
	    		  + " `update_time` varchar(20) DEFAULT NULL," + "\n"
	    		  + " `unit_count` int(11) NOT NULL DEFAULT '0'," + "\n"
			+ " PRIMARY KEY (`order_product_id`)");
	    sb.append("\n");
	    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    sb.append("\n \n");
	    //update
	    if (null != orderProductsListList && orderProductsListList.size() > 0) {
			for (OrderProducts orderProducts : orderProductsListList) {
				sb.append("INSERT INTO `dh_order_products` VALUES (");
			    sb.append(
			 	"'"+stringIsNull(orderProducts.getOrderProductId())+"'"+
			    ", '"+stringIsNull(orderProducts.getOrderId())+"'"+
			    ", '"+stringIsNull(orderProducts.getProductId())+"'"+
			 	", '"+stringIsNull(orderProducts.getProductName())+"'"+
			 	", '"+stringIsNull(orderProducts.getAlias())+"'"+
			 	", "+orderProducts.getProductType()+
			 	", "+orderProducts.getOrderType()+
			 	", '"+stringIsNull(orderProducts.getResCategoryId())+"'"+
			 	", '"+stringIsNull(orderProducts.getResCategoryName())+"'"+
			 	", '"+stringIsNull(orderProducts.getPublishYear())+"'"+
			 	", '"+stringIsNull(orderProducts.getPublishMonth())+"'"+
			 	", '"+stringIsNull(orderProducts.getInstitutionsId())+"'"+
			 	", '"+stringIsNull(orderProducts.getUpInstitutionsId())+"'"+
			 	", '"+stringIsNull(orderProducts.getProductAbbreviation())+"'"+
			 	", '"+stringIsNull(orderProducts.getStartYear())+"'"+
			 	", '"+stringIsNull(orderProducts.getEndYear())+"'"+
			 	", '"+stringIsNull(orderProducts.getProductPrice())+"'"+
			 	", '"+stringIsNull(orderProducts.getReserveEndDate())+"'"+
			 	", "+orderProducts.getReserveNumber()+
			 	", '"+stringIsNull(orderProducts.getCreateTime())+"'"+
			 	", '"+stringIsNull(orderProducts.getUpdateTime())+"'"+
				", "+orderProducts.getUnitCount()+");");
			    sb.append("\n");
			}
		}
	    sb.append("\n \n \n");*/
	    
	    /*sb.append("-- ----------------------------------------- \n ");
	    sb.append("-- dh_order_resource_products_detail ------- \n ");
	    sb.append("-- ----------------------------------------- \n ");
	    //12订单产品资源明细列表离线数据包：全量升级
	    List<OrderResourceProductsDetail> orderResourceProductsDetailList = exportInstitutionListByIdVo.getOrderResourceProductsDetailList();
	    sb.append("DROP TABLE IF EXISTS `dh_order_resource_products_detail`;");
	    sb.append("\n");
	    
	    sb.append("CREATE TABLE `dh_order_resource_products_detail` (");
	    sb.append("\n");
	    sb.append(" `order_resource_products_detail_id` varchar(32) NOT NULL," + "\n"
	    		 + " `order_id` varchar(32) NOT NULL," + "\n"
	    		  + " `order_product_id` varchar(32) NOT NULL," + "\n"
	    		  + " `product_id` varchar(32) NOT NULL," + "\n"
	    		  + " `product_name` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `product_type` int(11) NOT NULL DEFAULT '0' COMMENT '0：资源分类  1:资源'," + "\n"
	    		  + " `res_type_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `res_table` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `res_type_name` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `publishdate` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `order_type` int(11) DEFAULT NULL," + "\n"
	    		  + " `publishyear` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `publishmonth` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `institutions_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `up_institutions_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `res_category_id` varchar(32) NOT NULL," + "\n"
	    		  + " `res_category_name` varchar(200) NOT NULL," + "\n"
	    		  + " `up_res_category_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `alias` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `product_abbreviation` varchar(10) DEFAULT NULL," + "\n"
	    		  + " `create_time` varchar(20) DEFAULT NULL," + "\n"
	    		  + " `product_price` varchar(20) DEFAULT NULL," + "\n"
	    		  + " `unit_count` int(11) DEFAULT '0'," + "\n"
			+ " PRIMARY KEY (`order_resource_products_detail_id`)");
	    sb.append("\n");
	    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    sb.append("\n \n");
	    //update
	    if (null != orderResourceProductsDetailList && orderResourceProductsDetailList.size() > 0) {
			for (OrderResourceProductsDetail orderResourceProductsDetail : orderResourceProductsDetailList) {
				sb.append("INSERT INTO `dh_order_products` VALUES (");
			    sb.append(
			 	"'"+stringIsNull(orderResourceProductsDetail.getOrderResourceProductsDetailId())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getOrderId())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getOrderProductId())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getProductId())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getProductName())+"'"+
			    ", "+orderResourceProductsDetail.getProductType()+
			    ", '"+stringIsNull(orderResourceProductsDetail.getResTypeId())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getResTable())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getResTypeName())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getPublishdate())+"'"+
			    ", "+orderResourceProductsDetail.getOrderType()+
			    ", '"+stringIsNull(orderResourceProductsDetail.getPublishyear())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getPublishmonth())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getInstitutionsId())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getUpInstitutionsId())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getResCategoryId())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getResCategoryName())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getUpResCategoryId())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getAlias())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getProductAbbreviation())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getCreateTime())+"'"+
			    ", '"+stringIsNull(orderResourceProductsDetail.getProductPrice())+"'"+
				", "+orderResourceProductsDetail.getUnitCount()+");");
			    sb.append("\n");
			}
		}
	    sb.append("\n \n \n");*/
	    
	    
	    /*sb.append("-- ----------------------------------------- \n ");
	    sb.append("-- dh_order_resourse_price ----------------- \n ");
	    sb.append("-- ----------------------------------------- \n ");
	    //13、订单目录价格表离线数据包？？？？：全量升级
	    List<OrderResoursePrice> orderResoursePricesList = exportInstitutionListByIdVo.getOrderResoursePricesList();
	    sb.append("DROP TABLE IF EXISTS `dh_order_resourse_price`;");
	    sb.append("\n");
	    sb.append("CREATE TABLE `dh_order_resourse_price` (");
	    sb.append("\n");
	    sb.append(" `order_price_id` varchar(32) NOT NULL," + "\n"
    		  + " `order_id` varchar(32) NOT NULL," + "\n"
    		  + " `order_product_id` varchar(32) NOT NULL," + "\n"
    		  + " `res_category_id` varchar(32) NOT NULL," + "\n"
    		  + " `order_type` int(1) DEFAULT '0'," + "\n"
    		  + " `product_type` int(1) DEFAULT '0'," + "\n"
    		  + " `totalPrice` varchar(100) NOT NULL," + "\n"
			  + " PRIMARY KEY (`order_price_id`)");
	    sb.append("\n");
	    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
	    sb.append("\n \n");
	    //update
	    if (null != orderResoursePricesList && orderResoursePricesList.size() > 0) {
			for (OrderResoursePrice orderResoursePrice : orderResoursePricesList) {
				sb.append("INSERT INTO `dh_order_products` VALUES (");
			    sb.append(
			 	"'"+stringIsNull(orderResoursePrice.getOrderPriceId())+"'"+
			    ", '"+stringIsNull(orderResoursePrice.getOrderId())+"'"+
			    ", '"+stringIsNull(orderResoursePrice.getOrderProductId())+"'"+
			    ", '"+stringIsNull(orderResoursePrice.getResCategoryId())+"'"+
			    ", "+orderResoursePrice.getOrderType()+
			    ", "+orderResoursePrice.getProductType()+
				", "+stringIsNull(orderResoursePrice.getTotalprice())+");");
			    sb.append("\n");
			}
		}
	    sb.append("\n \n \n");*/
	    
	    
	    //12.1通过机构id，获取机构所有订单列表离线数据包：全量升级
//	    List<OrderPublishVo> orderPublishVoLists = exportInstitutionListByIdVo.getOrderPublishVoLists();
	    List<Orders> ordersList = exportInstitutionListByIdVo.getOrdersList();
	    if (null != ordersList && ordersList.size() > 0) {
		    
		    
		    
		    
//	    	for (OrderPublishVo orderPublishVo : orderPublishVoLists) {
		    	//1、获取订单离线数据包：全量升级
				List<Orders> ordersLists = exportInstitutionListByIdVo.getOrdersList();
				sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_orders ------------------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_orders`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_orders` (");
			    sb.append("\n");
			    sb.append(" `order_id` varchar(32) NOT NULL," + "\n"
					+ " `user_id` varchar(32) NOT NULL," + "\n"
					+ " `cgs_institution_id` varchar(32) NOT NULL," + "\n"
					+ " `institution_id` varchar(32) NOT NULL," + "\n"
					+ " `products_price` decimal(18,2) NOT NULL DEFAULT '0.00'," + "\n"
					+ " `freight_price` decimal(18,2) NOT NULL DEFAULT '0.00'," + "\n"
					+ " `total_price` decimal(18,2) NOT NULL DEFAULT '0.00'," + "\n"
//					+ " `is_unrestricted` int(11) NOT NULL DEFAULT '0'," + "\n"
					+ " `create_date` datetime NOT NULL," + "\n"
					+ " `end_date` datetime DEFAULT NULL," + "\n"
					+ " `pay_type` int(11) DEFAULT '2'," + "\n"
					+ " `pay_status` int(11) DEFAULT '0'," + "\n"
					+ " `pay_identifier` varchar(52) DEFAULT ''," + "\n"
					+ " `pay_date` datetime DEFAULT NULL,"+ "\n"
					+ " `cancel_date` datetime DEFAULT NULL,"+ "\n"
					+ " `cancel_reason` varchar(200) DEFAULT '',"+ "\n"
					+ " `cancel_type` int(2) DEFAULT NULL,"+ "\n"
					+ " `state` int(1) DEFAULT '0',"+ "\n"
					+ " `sync_state` int(1) DEFAULT '0',"+ "\n"
					+ " `copy_count` int(11) DEFAULT '0',"+ "\n"
					+ " `remark` varchar(200) DEFAULT NULL," + "\n"
					+ " `consignee_message_id` varchar(32) DEFAULT NULL," + "\n"
					+ " `deliver_type` int(11) DEFAULT '2'," + "\n"
					+ " `deliver_date` datetime DEFAULT NULL,"+ "\n"
					+ " `order_type` int(11) DEFAULT '1',"+ "\n"
					+ " `install_user_id` varchar(32) DEFAULT NULL,"+ "\n"
					+ " `push_user_id` varchar(32) DEFAULT NULL,"+ "\n"
					+ " `order_category` int(11) DEFAULT NULL," + "\n"
					+ " `upgrade_status` int(11) DEFAULT NULL," + "\n"
					+ " PRIMARY KEY (`order_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
				if (null != ordersLists && ordersLists.size()>0) {
					for (Orders orders : ordersLists) {
						sb.append("INSERT INTO `dh_orders` VALUES (");
					    sb.append(
					 	"'"+stringIsNull(orders.getOrderId())+"'"+
					    ", '"+stringIsNull(orders.getUserId())+"'"+
					    ", '"+stringIsNull(orders.getCgsInstitutionId())+"'"+
					 	", '"+stringIsNull(orders.getInstitutionId())+"'"+
					 	", "+orders.getProductsPrice()+
					 	", "+orders.getFreightPrice()+
					 	", "+orders.getTotalPrice()+
					 	//订单取消 IsUnrestricted  字段
					/* 	", "+orders.getIsUnrestricted()+*/
					 	", "+dateIsNull(DateUtil.formatToString(orders.getCreateDate()))+
					 	", "+dateIsNull(DateUtil.formatToString(orders.getEndDate()))+
					 	", "+orders.getPayType()+
					 	", "+orders.getPayStatus()+
					 	", '"+stringIsNull(orders.getPayIdentifier())+"'"+
					 	", "+dateIsNull(DateUtil.formatToString(orders.getPayDate()))+
					 	", "+dateIsNull(DateUtil.formatToString(orders.getCancelDate()))+
					 	", '"+stringIsNull(orders.getCancelReason())+"'"+
					 	", "+orders.getCancelType()+
					 	", "+orders.getState()+
					 	", "+orders.getSyncState()+
					 	", "+orders.getCopyCount()+
					 	", '"+stringIsNull(orders.getRemark())+"'"+
					 	", '"+stringIsNull(orders.getConsigneeMessageId())+"'"+
					 	", "+orders.getDeliverType()+
					 	", "+dateIsNull(DateUtil.formatToString(orders.getDeliverDate()))+
					 	", "+orders.getOrderType()+
					 	//订单取消合同编号   发票编号
					 /*	", '"+stringIsNull(orders.getInvoiceNo())+"'"+
					 	", '"+stringIsNull(orders.getContractNo())+"'"+*/
					 	", '"+stringIsNull(orders.getInstallUserId())+"'"+
					 	", '"+stringIsNull(orders.getPushUserId())+"'"+
					    ", '"+orders.getOrderCategory()+"'"+
					    ", '"+orders.getUpgradeStatus()+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    /**
			    //2、获取合同离线数据包：全量升级
				List<Contract> contractList = exportInstitutionListByIdVo.getContractList();
				sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_contract ----------------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_contract`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_contract` (");
			    sb.append("\n");
			    sb.append(" `contract_id` varchar(32) NOT NULL," + "\n"
	    		  + " `contract_no` varchar(20) NOT NULL," + "\n"
	    		  + " `order_id` varchar(32) NOT NULL," + "\n"
	    		  + " `jf_institution_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `jf_institution_name` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `jf_user_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `yf_institution_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `yf_institution_name` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `yf_user_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `create_date` datetime DEFAULT NULL," + "\n"
	    		  + " `contract_validity` varchar(10) DEFAULT NULL," + "\n"
	    		  + " `contract_scans_file_url` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `contract_amount` varchar(20) DEFAULT NULL," + "\n"
	    		  + " `contract_back_schedule` varchar(10) DEFAULT ''," + "\n"
	    		  + " `update_date` datetime DEFAULT NULL," + "\n"
	    		  + " `contract_back_status` int(11) DEFAULT NULL," + "\n"
	    		  + " `remarks` varchar(255) DEFAULT NULL," + "\n"
	    		  + " PRIMARY KEY (`contract_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
				if (null != contractList && contractList.size()>0) {
					for (Contract contract : contractList) {
						sb.append("INSERT INTO `dh_contract` VALUES (");
					    sb.append(
					 	"'"+stringIsNull(contract.getContractId())+"'"+
					    ", '"+stringIsNull(contract.getContractNo())+"'"+
					 			//合同取消  订单ID字段
					 	", '"+stringIsNull(contract.getJfInstitutionId())+"'"+
					 	", '"+stringIsNull(contract.getJfInstitutionName())+"'"+
					 	", '"+stringIsNull(contract.getJfUserId())+"'"+
					 	", '"+stringIsNull(contract.getYfInstitutionId())+"'"+
					 	", '"+stringIsNull(contract.getYfInstitutionName())+"'"+
					 	", '"+stringIsNull(contract.getYfUserId())+"'"+
					 	", "+dateIsNull(DateUtil.formatToString(contract.getCreateDate()))+
					 	", '"+stringIsNull(contract.getContractValidity())+"'"+
					 	", '"+stringIsNull(contract.getContractScansFileUrl())+"'"+
					 	", '"+stringIsNull(contract.getContractAmount())+"'"+
					 	", "+contract.getContractBackStatus()+
					 	", "+dateIsNull(DateUtil.formatToString(contract.getUpdateDate()))+
					 	", "+contract.getContractBackStatus()+
					 	", '"+stringIsNull(contract.getRemarks())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    //3.获取发票离线数据包：全量升级
			    List<Invoices> invoicesList = exportInstitutionListByIdVo.getInvoicesList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_invoices ----------------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_invoices`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_invoices` (");
			    sb.append("\n");
			    sb.append(" `invoice_id` varchar(32) NOT NULL," + "\n"
	    		  + " `invoice_no` varchar(20) NOT NULL," + "\n"
	    		  + " `user_id` varchar(32) DEFAULT ''," + "\n"
	    		  + " `order_id` varchar(32) NOT NULL," + "\n"
	    		  + " `create_date` datetime DEFAULT NULL," + "\n"
	    		  + " `invoice_amount` varchar(32) DEFAULT ''," + "\n"
	    		  + " `post_tax_amount` varchar(20) DEFAULT ''," + "\n"
	    		  + " `back_amount` varchar(20) DEFAULT ''," + "\n"
	    		  + " `back_date` varchar(20) DEFAULT ''," + "\n"
	    		  + " `back_proportion` varchar(10) DEFAULT ''," + "\n"
	    		  + " `not_back_amount` varchar(20) DEFAULT ''," + "\n"
	    		  + " `back_year` varchar(4) DEFAULT ''," + "\n"
	    		  + " `create_user_id` varchar(32) DEFAULT ''," + "\n"
	    		  + " `financial_account_number` varchar(32) DEFAULT ''," + "\n"
	    		  + " `send_invoice_date` datetime DEFAULT NULL," + "\n"
	    		  + " `waybill_number` varchar(32) DEFAULT ''," + "\n"
	    		  + " `update_date` datetime DEFAULT NULL," + "\n"
	    		  + " `invoice_status` int(11) DEFAULT NULL," + "\n"
	    		  + " `cancel_invoice_reason` varchar(255) DEFAULT ''," + "\n"
	    		  + " `remarks` varchar(255) DEFAULT ''," + "\n"
	    		  + " PRIMARY KEY (`invoice_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != invoicesList && invoicesList.size()>0) {
					for (Invoices invoices : invoicesList) {
						sb.append("INSERT INTO `dh_invoices` VALUES (");
					    sb.append(
					 	"'"+stringIsNull(invoices.getInvoiceId())+"'"+
					    ", '"+stringIsNull(invoices.getInvoiceNo())+"'"+
					    ", '"+stringIsNull(invoices.getUserId())+"'"+
					    //发票取消订单ID字段
					 	", "+dateIsNull(DateUtil.formatToString(invoices.getCreateDate()))+
					 	", '"+stringIsNull(invoices.getInvoiceAmount())+"'"+
					 	", '"+stringIsNull(invoices.getPostTaxAmount())+"'"+
					 	", '"+stringIsNull(invoices.getBackAmount())+"'"+
					 	", '"+stringIsNull(invoices.getBackDate())+"'"+
					 	", '"+stringIsNull(invoices.getBackProportion())+"'"+
					 	", '"+stringIsNull(invoices.getNotBackAmount())+"'"+
					 	", '"+stringIsNull(invoices.getBackYear())+"'"+
					 	", '"+stringIsNull(invoices.getCreateUserId())+"'"+
					 	", '"+stringIsNull(invoices.getFinancialAccountNumber())+"'"+
					 	", "+dateIsNull(DateUtil.formatToString(invoices.getSendInvoiceDate()))+
						", '"+stringIsNull(invoices.getWaybillNumber())+"'"+
						", "+dateIsNull(DateUtil.formatToString(invoices.getUpdateDate()))+
						", "+invoices.getInvoiceStatus()+
						", '"+stringIsNull(invoices.getCancelInvoiceReason())+"'"+
					 	", '"+stringIsNull(invoices.getRemarks())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
				
				**/
			    //4.获取产品离线数据包：全量升级
			    List<OrderProducts> orderProductsList = exportInstitutionListByIdVo.getOrderProductsList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_order_products ----------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_order_products`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_order_products` (");
			    sb.append("\n");
			    sb.append(" `order_product_id` varchar(32) NOT NULL," + "\n"
			    	  + " `order_id` varchar(32) NOT NULL," + "\n"
		    		  + " `product_id` varchar(32) NOT NULL," + "\n"
		    		  + " `product_name` varchar(100) NOT NULL," + "\n"
		    		  + " `alias` varchar(50) DEFAULT NULL," + "\n"
		    		  + " `product_type` int(11) NOT NULL DEFAULT '0' COMMENT '0：资源分类  1:资源'," + "\n"
		    		  + " `order_type` int(11) NOT NULL DEFAULT '1'," + "\n"
		    		  + " `res_category_id` varchar(32) NOT NULL," + "\n"
		    		  + " `res_category_name` varchar(200) NOT NULL," + "\n"
		    		  + " `publishyear` varchar(4) DEFAULT NULL," + "\n"
		    		  + " `publishmonth` varchar(2) DEFAULT NULL," + "\n"
		    		  + " `institutions_id` varchar(32) NOT NULL," + "\n"
		    		  + " `up_institutions_id` varchar(32) NOT NULL," + "\n"
		    		  + " `product_abbreviation` varchar(10) DEFAULT NULL," + "\n"
		    		  + " `start_year` varchar(4) DEFAULT NULL," + "\n"
		    		  + " `end_year` varchar(4) DEFAULT NULL," + "\n"
		    		  + " `product_price` varchar(20) NOT NULL DEFAULT '0'," + "\n"
		    		  + " `reserve_end_date` varchar(10) DEFAULT NULL," + "\n"
		    		  + " `reserve_number` int(11) DEFAULT '0'," + "\n"
		    		  + " `create_time` varchar(20) NOT NULL," + "\n"
		    		  + " `update_time` varchar(20) DEFAULT NULL," + "\n"
		    		  + " `unit_count` int(11) NOT NULL DEFAULT '0'," + "\n"
		    		  + " PRIMARY KEY (`order_product_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != orderProductsList && orderProductsList.size()>0) {
			    	
					for (OrderProducts orderProducts : orderProductsList) {
						sb.append("INSERT INTO `dh_order_products` VALUES (");
					    sb.append(
					    	"'"+stringIsNull(orderProducts.getOrderProductId())+"'"+
		    			    ", '"+stringIsNull(orderProducts.getOrderId())+"'"+
		    			    ", '"+stringIsNull(orderProducts.getProductId())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getProductName())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getAlias())+"'"+
		    			 	", "+orderProducts.getProductType()+
		    			 	", "+orderProducts.getOrderType()+
		    			 	", '"+stringIsNull(orderProducts.getResCategoryId())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getResCategoryName())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getPublishYear())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getPublishMonth())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getInstitutionsId())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getUpInstitutionsId())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getProductAbbreviation())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getStartYear())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getEndYear())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getProductPrice())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getReserveEndDate())+"'"+
		    			 	", "+orderProducts.getReserveNumber()+
		    			 	", '"+stringIsNull(orderProducts.getCreateTime())+"'"+
		    			 	", '"+stringIsNull(orderProducts.getUpdateTime())+"'"+
		    				", "+orderProducts.getUnitCount()+");");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			   
			    //5.获取常用联系人离线数据包：全量升级
			    List<OftenConsignees> oftenConsigneesList = exportInstitutionListByIdVo.getOftenConsigneesList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_often_consignees --------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_often_consignees`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_often_consignees` (");
			    sb.append("\n");
			    sb.append(" `consignee_message_id` varchar(32) NOT NULL," + "\n"
	    		  + " `user_id` varchar(32) NOT NULL," + "\n"
	    		  + " `consignee_name` varchar(52) DEFAULT NULL," + "\n"
	    		  + " `receipt_address` varchar(200) DEFAULT NULL," + "\n"
	    		  + " `consignee_phone` varchar(30) DEFAULT NULL," + "\n"
	    		  + " `consignee_email` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `receipt_post_code` varchar(20) DEFAULT NULL," + "\n"
	    		  + " `update_date` datetime DEFAULT NULL," + "\n"
	    		  + " PRIMARY KEY (`consignee_message_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != oftenConsigneesList && oftenConsigneesList.size()>0) {
					for (OftenConsignees oftenConsignees : oftenConsigneesList) {
						sb.append("INSERT INTO `dh_often_consignees` VALUES (");
					    sb.append(
					 	"'"+stringIsNull(oftenConsignees.getConsigneeMessageId())+"'"+
					    ", '"+stringIsNull(oftenConsignees.getUserId())+"'"+
					    ", '"+stringIsNull(oftenConsignees.getConsigneeName())+"'"+
					 	", '"+stringIsNull(oftenConsignees.getReceiptAddress())+"'"+
					 	", '"+stringIsNull(oftenConsignees.getConsigneePhone())+"'"+
					 	", '"+stringIsNull(oftenConsignees.getConsigneeEmail())+"'"+
					 	", '"+stringIsNull(oftenConsignees.getReceiptPostCode())+"'"+
					 	", "+dateIsNull(DateUtil.formatToString(oftenConsignees.getUpdateDate()))+");");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    //6.获取订单记录离线数据包：全量升级
			    List<OrderProcesses> orderProcessesList = exportInstitutionListByIdVo.getOrderProcessesList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_order_processes ---------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_order_processes`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_order_processes` (");
			    sb.append("\n");
			    sb.append(" `order_process_id` varchar(32) NOT NULL," + "\n"
	    		  + " `order_id` varchar(32) NOT NULL," + "\n"
	    		  + " `institution_id` varchar(32) NOT NULL," + "\n"
	    		  + " `institution_Name` varchar(100) NOT NULL," + "\n"
	    		  + " `user_id` varchar(32) NOT NULL," + "\n"
	    		  + " `user_name` varchar(52) NOT NULL," + "\n"
	    		  + " `process_message` varchar(200) DEFAULT NULL," + "\n"
	    		  + " `process_date` datetime NOT NULL," + "\n"
	    		  + " `process_type` int(11) NOT NULL DEFAULT '2'," + "\n"
	    		  + " `process_ip` varchar(30) DEFAULT NULL," + "\n"
	    		  + " `order_status` int(11) NOT NULL DEFAULT '3'," + "\n"
	    		  + " PRIMARY KEY (`order_process_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != orderProcessesList && orderProcessesList.size()>0) {
					for (OrderProcesses orderProcesses : orderProcessesList) {
						sb.append("INSERT INTO `dh_order_processes` VALUES (");
					    sb.append(
					 	"'"+stringIsNull(orderProcesses.getOrderProcessId())+"'"+
					    ", '"+stringIsNull(orderProcesses.getOrderId())+"'"+
					    ", '"+stringIsNull(orderProcesses.getInstitutionId())+"'"+
					 	", '"+stringIsNull(orderProcesses.getInstitutionName())+"'"+
					 	", '"+stringIsNull(orderProcesses.getUserId())+"'"+
					 	", '"+stringIsNull(orderProcesses.getUserName())+"'"+
					 	", '"+stringIsNull(orderProcesses.getProcessMessage())+"'"+
					 	", "+dateIsNull(DateUtil.formatToString(orderProcesses.getProcessDate()))+
					 	", "+orderProcesses.getProcessType()+
					 	", '"+stringIsNull(orderProcesses.getProcessIp())+"'"+
					 	", "+orderProcesses.getOrderStatus()+");");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    //7.获取资源分类离线数据包：增量升级
			    List<ResourceCategors> resourceCategorysList = exportInstitutionListByIdVo.getResourceCategorysList();
			    if (null != resourceCategorysList && resourceCategorysList.size()>0) {
					for (ResourceCategors resourceCategors : resourceCategorysList) {
						sb.append("INSERT INTO `dh_resource_categorys`("
								+ "`res_category_id`,`res_name`,`parent_id`,`description`,`category_order`,"
				    			+ "`is_publications`)");
						sb.append("SELECT ");
					    sb.append(
					 	"'"+stringIsNull(resourceCategors.getResCategoryId())+"'"+
					    ", '"+stringIsNull(resourceCategors.getResName())+"'"+
					    ", '"+stringIsNull(resourceCategors.getParentId())+"'"+
					 	", '"+stringIsNull(resourceCategors.getDescription())+"'"+
					 	", '"+stringIsNull(resourceCategors.getCategoryOrder())+"'"+
					 	", '"+resourceCategors.getIsPublications()+"'");
					    sb.append(" FROM DUAL WHERE NOT EXISTS(");
				    	sb.append("SELECT `res_category_id` FROM `dh_resource_categorys` WHERE `res_category_id` = "+"'"+resourceCategors.getResCategoryId()+"');\n");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    //8.获取资源离线数据包：全量升级
			    List<Resources> resourcesList = exportInstitutionListByIdVo.getResourcesList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_resources ---------------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_resources`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_resources` (");
			    sb.append("\n");
			    sb.append(" `res_id` varchar(32) NOT NULL," + "\n"
	    		  + " `res_name` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `res_type_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `publish_date` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `thumbnail` varchar(500) DEFAULT NULL," + "\n"
	    		  + " `price` varchar(20) DEFAULT NULL," + "\n"
	    		  + " `favorite_count` int(11) DEFAULT NULL," + "\n"
	    		  + " `share_count` int(11) DEFAULT NULL," + "\n"
	    		  + " `use_count` int(11) DEFAULT NULL," + "\n"
	    		  + " `keyword` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `status` int(11) DEFAULT NULL," + "\n"
	    		  + " `create_user_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `create_date` date DEFAULT NULL," + "\n"
	    		  + " `last_updated_user_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `last_updated_date` date DEFAULT NULL," + "\n"
	    		  + " PRIMARY KEY (`res_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != resourcesList && resourcesList.size()>0) {
					for (Resources resources : resourcesList) {
						sb.append("INSERT INTO `dh_resources` VALUES (");
					    sb.append(
					 	"'"+stringIsNull(resources.getResId())+"'"+
					    ", '"+stringReplace(resources.getResName())+"'"+
					    ", '"+stringIsNull(resources.getResTypeId())+"'"+
					 	", '"+stringIsNull(resources.getPublishDate())+"'"+
					 	", '"+stringIsNull(resources.getThumbnail())+"'"+
					 	", '"+stringIsNull(resources.getPrice())+"'"+
					    ", "+resources.getFavoriteCount()+
					 	", "+resources.getShareCount()+
					 	", "+resources.getUseCount()+
					 	", '"+stringIsNull(resources.getKeyword())+"'"+
					    ", "+resources.getStatus()+
					 	", '"+stringIsNull(resources.getCreateUserId())+"'"+
					 	", "+dateIsNull(DateUtil.formatToString(resources.getCreateDate()))+
					 	", '"+stringIsNull(resources.getLastUpdatedUserId())+"'"+
					 	", "+dateIsNull(DateUtil.formatToString(resources.getLastUpdatedDate()))+");");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    //9.获取资源关系离线数据包：全量升级
			    List<ResourceRelations> resourceRelationsList = exportInstitutionListByIdVo.getResourceRelationsList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_resource_relations ------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_resource_relations`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_resource_relations` (");
			    sb.append("\n");
			    sb.append(" `res_relation_id` varchar(32) NOT NULL," + "\n"
	    		  + " `frist_res_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `second_res_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `relation_type` int(2) DEFAULT NULL," + "\n"
	    		  + " PRIMARY KEY (`res_relation_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != resourceRelationsList && resourceRelationsList.size()>0) {
					for (ResourceRelations resourceRelations : resourceRelationsList) {
						sb.append("INSERT INTO `dh_resource_relations` VALUES (");
					    sb.append(
						 	"'"+stringIsNull(resourceRelations.getResRelationId())+"'"+
						    ", '"+stringIsNull(resourceRelations.getFristResId())+"'"+
						    ", '"+stringIsNull(resourceRelations.getSecondResId())+"'"+
						 	", "+resourceRelations.getRelationType()+");");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    //10.获取资源分类关系离线数据包：全量升级
			    List<ResCategoryRelations> resCategoryRelationsList = exportInstitutionListByIdVo.getResCategoryRelationsList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_resource_category_relations ---------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_resource_category_relations`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_resource_category_relations` (");
			    sb.append("\n");
			    sb.append(" `res_category_relation_id` varchar(32) NOT NULL," + "\n"
	    		  + " `res_category_id` varchar(32) NOT NULL," + "\n"
	    		  + " `res_id` varchar(32) NOT NULL," + "\n"
	    		  + " PRIMARY KEY (`res_category_relation_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != resCategoryRelationsList && resCategoryRelationsList.size()>0) {
					for (ResCategoryRelations resCategoryRelations : resCategoryRelationsList) {
						sb.append("INSERT INTO `dh_resource_category_relations` VALUES (");
					    sb.append(
						 	"'"+stringIsNull(resCategoryRelations.getResCategoryRelationId())+"'"+
						    ", '"+stringIsNull(resCategoryRelations.getResCategoryId())+"'"+
						 	", '"+stringIsNull(resCategoryRelations.getResId())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    //11.获取文章内容离线数据包：全量升级
			    List<ArticleContents> articleContentsList = exportInstitutionListByIdVo.getArticleContentsList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_article_contents --------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_article_contents`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_article_contents` (");
			    sb.append("\n");
			    sb.append(" `res_id` varchar(32) NOT NULL," + "\n"
	    		  + " `content` text," + "\n"
	    		  + " PRIMARY KEY (`res_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != articleContentsList && articleContentsList.size()>0) {
					for (ArticleContents articleContents : articleContentsList) {
						sb.append("INSERT INTO `dh_article_contents` VALUES (");
					    sb.append(
						 	"'"+stringIsNull(articleContents.getResId())+"'"+
						 	", '"+stringReplace(articleContents.getContent())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    //12.获取文章离线数据包：全量升级
			    List<Articles> articlesList = exportInstitutionListByIdVo.getArticlesList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_articles ----------------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_articles`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_articles` (");
			    sb.append("\n");
			    sb.append(" `res_id` varchar(32) NOT NULL," + "\n"
	    		  + " `article_type` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `columnes` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `sub_title` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `author` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `translator` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `cip` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `keyword` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `page` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `pages` text," + "\n"
	    		  + " `start_page` int(11) DEFAULT NULL," + "\n"
	    		  + " `end_page` int(11) DEFAULT NULL," + "\n"
	    		  + " `description` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `painter` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `source` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `page_scope` varchar(255) DEFAULT NULL," + "\n"
	    		  + " PRIMARY KEY (`res_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != articlesList && articlesList.size()>0) {
					for (Articles articles : articlesList) {
						sb.append("INSERT INTO `dh_articles` VALUES (");
					    sb.append(
						 	"'"+stringIsNull(articles.getResId())+"'"+
						 	", '"+stringIsNull(articles.getArticleType())+"'"+
				 			", '"+stringReplace(articles.getColumnes())+"'"+
				 			", '"+stringReplace(articles.getSubTitle())+"'"+
				 			", '"+stringIsNull(articles.getAuthor())+"'"+
				 			", '"+stringIsNull(articles.getTranslator())+"'"+
				 			", '"+stringIsNull(articles.getCip())+"'"+
				 			", '"+stringIsNull(articles.getKeyword())+"'"+
				 			", '"+stringIsNull(articles.getPage())+"'"+
				 			", '"+stringIsNull(articles.getPages())+"'"+
				 			", "+articles.getStartPage()+
				 			", "+articles.getEndPage()+
				 			", '"+stringReplace(articles.getDescription())+"'"+
				 			", '"+stringIsNull(articles.getPainter())+"'"+
				 			", '"+stringIsNull(articles.getSource())+"'"+
						 	", '"+stringIsNull(articles.getPageScope())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    //13.获取图书离线数据包：全量升级
			    List<Books> booksList = exportInstitutionListByIdVo.getBooksList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_books -------------------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_books`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_books` (");
			    sb.append("\n");
			    sb.append(" `res_id` varchar(32) NOT NULL DEFAULT ''," + "\n"
	    		  + " `author` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `translator` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `publisher` varchar(52) DEFAULT NULL," + "\n"
	    		  + " `isbn` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `front_cover` varchar(500) DEFAULT NULL," + "\n"
	    		  + " `editor` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `drawer` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `price` varchar(20) DEFAULT NULL," + "\n"
	    		  + " `remark_level` int(11) DEFAULT NULL," + "\n"
	    		  + " `dynasty` varchar(52) DEFAULT NULL," + "\n"
	    		  + " `a_nationality` varchar(52) DEFAULT NULL," + "\n"
	    		  + " `e_nationality` varchar(52) DEFAULT NULL," + "\n"
	    		  + " `t_nationality` varchar(52) DEFAULT NULL," + "\n"
	    		  + " `d_nationality` varchar(52) DEFAULT NULL," + "\n"
	    		  + " `category` char(50) DEFAULT NULL," + "\n"
	    		  + " `alias` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `sereis` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `is_input` bit(1) DEFAULT NULL," + "\n"
	    		  + " `is_original` bit(1) DEFAULT NULL," + "\n"
	    		  + " `is_phonetic` bit(1) DEFAULT NULL," + "\n"
	    		  + " `is_phonetic_book` bit(1) DEFAULT NULL," + "\n"
	    		  + " `min_age` int(11) DEFAULT NULL," + "\n"
	    		  + " `max_age` int(11) DEFAULT NULL," + "\n"
	    		  + " `description` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `edition` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `binding_style` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `language` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `page_count` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `reading_object` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `age` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `source_path` varchar(500) DEFAULT NULL," + "\n"
	    		  + " PRIMARY KEY (`res_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != booksList && booksList.size()>0) {
					for (Books books : booksList) {
						sb.append("INSERT INTO `dh_books` VALUES (");
					    sb.append(
						 	"'"+stringIsNull(books.getResId())+"'"+
				 			", '"+stringIsNull(books.getAuthor())+"'"+
				 			", '"+stringIsNull(books.getTranslator())+"'"+
				 			", '"+stringIsNull(books.getPublisher())+"'"+
				 			", '"+stringIsNull(books.getIsbn())+"'"+
				 			", '"+stringIsNull(books.getFrontCover())+"'"+
				 			", '"+stringIsNull(books.getEditor())+"'"+
				 			", '"+stringIsNull(books.getDrawer())+"'"+
				 			", '"+stringIsNull(books.getPrice())+"'"+
				 			", "+books.getRemarkLevel()+
				 			", '"+stringIsNull(books.getDynasty())+"'"+
				 			", '"+stringIsNull(books.getaNationality())+"'"+
				 			", '"+stringIsNull(books.geteNationality())+"'"+
				 			", '"+stringIsNull(books.gettNationality())+"'"+
				 			", '"+stringIsNull(books.getdNationality())+"'"+
				 			", '"+stringIsNull(books.getCategory())+"'"+
				 			", '"+stringIsNull(books.getAlias())+"'"+
				 			", '"+stringIsNull(books.getSereis())+"'"+
				 			", "+books.getIsInput()+
				 			", "+books.getIsOriginal()+
				 			", "+books.getIsPhonetic()+
				 			", "+books.getIsPhoneticBook()+
				 			", "+books.getMinAge()+
				 			", "+books.getMaxAge()+
				 			", '"+stringIsNull(books.getDescription())+"'"+
				 			", '"+stringIsNull(books.getEdition())+"'"+
				 			", '"+stringIsNull(books.getBindingStyle())+"'"+
				 			", '"+stringIsNull(books.getLanguage())+"'"+
				 			", '"+stringIsNull(books.getPageCount())+"'"+
				 			", '"+stringIsNull(books.getReadingObject())+"'"+
				 			", '"+stringIsNull(books.getAge())+"'"+
						 	", '"+stringIsNull(books.getSourcePath())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    
			    //14.获取游戏离线数据包：全量升级
			    List<Games> gamesList = exportInstitutionListByIdVo.getGamesList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_games -------------------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_games`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_games` (");
			    sb.append("\n");
			    sb.append(" `res_id` varchar(32) NOT NULL DEFAULT ''," + "\n"
	    		  + " `front_cover` varchar(100) NOT NULL," + "\n"
	    		  + " `games_type` varchar(100) NOT NULL," + "\n"
	    		  + " `games_size` double NOT NULL," + "\n"
	    		  + " `file_type` varchar(100) NOT NULL," + "\n"
	    		  + " `description` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `source_path` varchar(500) DEFAULT NULL," + "\n"
	    		  + " PRIMARY KEY (`res_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != gamesList && gamesList.size()>0) {
					for (Games games : gamesList) {
						sb.append("INSERT INTO `dh_games` VALUES (");
					    sb.append(
						 	"'"+stringIsNull(games.getResId())+"'"+
						 	", '"+stringIsNull(games.getFrontCover())+"'"+
				 			", '"+stringIsNull(games.getGamesType())+"'"+
				 			", "+games.getGamesSize()+
				 			", '"+stringIsNull(games.getFileType())+"'"+
				 			", '"+stringIsNull(games.getDescription())+"'"+
						 	", '"+stringIsNull(games.getSourcePath())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    //15.获取音视频离线数据包：全量升级
			    List<Videos> videosList = exportInstitutionListByIdVo.getVideosList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_videos ------------------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_videos`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_videos` (");
			    sb.append("\n");
			    sb.append(" `res_id` varchar(32) NOT NULL," + "\n"
	    		  + " `front_cover` varchar(500) DEFAULT NULL," + "\n"
	    		  + " `video_type` int(200) DEFAULT NULL," + "\n"
	    		  + " `video_size` varchar(200) DEFAULT NULL," + "\n"
	    		  + " `video_length` varchar(200) DEFAULT NULL," + "\n"
	    		  + " `file_type` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `base_type` int(11) DEFAULT '1'," + "\n"
	    		  + " `format` int(11) DEFAULT '1'," + "\n"
	    		  + " `literal_writer` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `photographer` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `shooting_address` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `source` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `book_column` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `ages` varchar(20) DEFAULT NULL," + "\n"
	    		  + " `master` varchar(50) DEFAULT NULL," + "\n"
	    		  + " `frame_amount` varchar(200) DEFAULT NULL," + "\n"
	    		  + " `description` varchar(2000) DEFAULT NULL," + "\n"
	    		  + " `source_path` varchar(500) DEFAULT NULL," + "\n"
	    		  + " PRIMARY KEY (`res_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != videosList && videosList.size()>0) {
					for (Videos videos : videosList) {
						sb.append("INSERT INTO `dh_videos` VALUES (");
					    sb.append(
						 	"'"+stringIsNull(videos.getResId())+"'"+
						 	", '"+stringIsNull(videos.getFrontCover())+"'"+
						 	", "+videos.getVideoType()+
						 	", '"+stringIsNull(videos.getVideoSize())+"'"+
						 	", '"+stringIsNull(videos.getVideoLength())+"'"+
						 	", '"+stringIsNull(videos.getFileType())+"'"+
						 	", "+videos.getBaseType()+
						 	", "+videos.getFormat()+
						 	", '"+stringIsNull(videos.getLiteralWriter())+"'"+
						 	", '"+stringIsNull(videos.getPhotographer())+"'"+
						 	", '"+stringIsNull(videos.getShootingAddress())+"'"+
						 	", '"+stringIsNull(videos.getSource())+"'"+
						 	", '"+stringIsNull(videos.getBookColumn())+"'"+
						 	", '"+stringIsNull(videos.getAges())+"'"+
						 	", '"+stringIsNull(videos.getMaster())+"'"+
						 	", '"+stringIsNull(videos.getFrameAmount())+"'"+
						 	", '"+stringIsNull(videos.getDescription())+"'"+
						 	", '"+stringIsNull(videos.getSourcePath())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    //16.获取报刊离线数据包：全量升级
			    List<Magazines> magazinesList = exportInstitutionListByIdVo.getMagazinesList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_magazines ---------------------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_magazines`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_magazines` (");
			    sb.append("\n");
			    sb.append(" `res_id` varchar(32) NOT NULL," + "\n"
	    		  + " `year` int(11) DEFAULT NULL," + "\n"
	    		  + " `month` int(11) DEFAULT NULL," + "\n"
	    		  + " `period_of_time` varchar(52) DEFAULT NULL," + "\n"
	    		  + " `publisher` varchar(25) DEFAULT NULL," + "\n"
	    		  + " `issn` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `isbn` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `cn` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `post_code` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `front_cover` varchar(250) DEFAULT NULL," + "\n"
	    		  + " `category` varchar(250) DEFAULT NULL," + "\n"
	    		  + " `alias` varchar(100) DEFAULT NULL," + "\n"
	    		  + " `age` varchar(10) DEFAULT NULL," + "\n"
	    		  + " `reading_object` varchar(20) DEFAULT NULL," + "\n"
	    		  + " `page_count` varchar(10) DEFAULT NULL," + "\n"
	    		  + " `description` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `source_path` varchar(500) DEFAULT NULL," + "\n"
	    		  + " PRIMARY KEY (`res_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != magazinesList && magazinesList.size()>0) {
					for (Magazines magazines : magazinesList) {
						sb.append("INSERT INTO `dh_magazines` VALUES (");
					    sb.append(
						 	"'"+stringIsNull(magazines.getResId())+"'"+
						 	", "+magazines.getYear()+
						 	", "+magazines.getMonth()+
						 	", '"+stringIsNull(magazines.getPeriodOfTime())+"'"+
						 	", '"+stringIsNull(magazines.getPublisher())+"'"+
						 	", '"+stringIsNull(magazines.getIssn())+"'"+
						 	", '"+stringIsNull(magazines.getIsbn())+"'"+
						 	", '"+stringIsNull(magazines.getCn())+"'"+
						 	", '"+stringIsNull(magazines.getPostCode())+"'"+
						 	", '"+stringIsNull(magazines.getFrontCover())+"'"+
						 	", '"+stringIsNull(magazines.getCategory())+"'"+
						 	", '"+stringIsNull(magazines.getAlias())+"'"+
						 	", '"+stringIsNull(magazines.getAge())+"'"+
						 	", '"+stringIsNull(magazines.getReadingObject())+"'"+
						 	", '"+stringIsNull(magazines.getPageCount())+"'"+
						 	", '"+stringIsNull(magazines.getDescription())+"'"+
						 	", '"+stringIsNull(magazines.getSourcePath())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    
			    //17.获取终端专属资源离线数据包：全量升级
			    List<SpecialResourceDatas> specialResourceDatasList = exportInstitutionListByIdVo.getSpecialResourceDatasList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_special_resource_datas --------------- \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_special_resource_datas`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_special_resource_datas` (");
			    sb.append("\n");
			    sb.append(" `special_res_data_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `res_id` varchar(32) DEFAULT NULL," + "\n"
	    		  + " `terminal_code` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `uri` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `uri_type` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `open_id` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `password_id` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `password` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `drm_id` varchar(255) DEFAULT NULL," + "\n"
	    		  + " `drm_password` varchar(255) DEFAULT NULL" + "\n");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    if (null != specialResourceDatasList && specialResourceDatasList.size()>0) {
					for (SpecialResourceDatas specialResourceDatas : specialResourceDatasList) {
						sb.append("INSERT INTO `dh_special_resource_datas` VALUES (");
					    sb.append(
						 	"'"+stringIsNull(specialResourceDatas.getSpecialResDataId())+"'"+
						 	", '"+stringIsNull(specialResourceDatas.getResId())+"'"+
						 	", '"+stringIsNull(specialResourceDatas.getTerminalCode())+"'"+
						 	", '"+stringIsNull(specialResourceDatas.getUri())+"'"+
						 	", '"+stringIsNull(specialResourceDatas.getUriType())+"'"+
						 	", '"+stringIsNull(specialResourceDatas.getOpenId())+"'"+
						 	", '"+stringIsNull(specialResourceDatas.getPasswordId())+"'"+
						 	", '"+stringIsNull(specialResourceDatas.getPassword())+"'"+
						 	", '"+stringIsNull(specialResourceDatas.getDrmId())+"'"+
						 	", '"+stringIsNull(specialResourceDatas.getDrmPassword())+"');");
					    sb.append("\n");
					}
					sb.append("\n \n");
				}
			    
			    //18.获取资源类型离线数据包：全量升级
			    List<ResourceType> resourceTypeList = exportInstitutionListByIdVo.getResourceTypeList();
			    sb.append("-- ----------------------------------------- \n");
				sb.append("-- dh_resource_type ------------------------ \n");
				sb.append("-- ----------------------------------------- \n");
			    sb.append("DROP TABLE IF EXISTS `dh_resource_type`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_resource_type` (");
			    sb.append("\n");
			    sb.append(" `res_type_id` varchar(32) NOT NULL," + "\n"
					+ " `name` varchar(255) DEFAULT NULL," + "\n"
					+ " `en_name` varchar(255) DEFAULT NULL," + "\n"
					+ " `res_table` varchar(255) DEFAULT NULL," + "\n"
					+ " `is_retail` int(11) DEFAULT NULL," + "\n"
					+ " `description` varchar(255) DEFAULT NULL," + "\n"
					+ " PRIMARY KEY (`res_type_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    //update
			    if (null != resourceTypeList && resourceTypeList.size() > 0) {
			    	 
					for (ResourceType resourceType : resourceTypeList) {
						sb.append("INSERT INTO `dh_resource_type` VALUES (");
			    	    sb.append(
			    	 	"'"+stringIsNull(resourceType.getResTypeId())+"'"+
			    	    ", '"+stringIsNull(resourceType.getName())+"'"+
			    	    ", '"+stringIsNull(resourceType.getEnName())+"'"+
			    	    ", '"+stringIsNull(resourceType.getResTable())+"'"+
			    	    ", "+resourceType.getIsRetail()+
					 	", '"+stringIsNull(resourceType.getDescription())+"');");
			    	    sb.append("\n");
					}
					sb.append("\n \n \n");
				}
			    
			    //12订单产品资源明细列表离线数据包：全量升级
			    List<OrderResourceProductsDetail> orderResourceProductsDetailList = exportInstitutionListByIdVo.getOrderResourceProductsDetailsList();
			    sb.append("-- ----------------------------------------- \n ");
			    sb.append("-- dh_order_resource_products_detail ------- \n ");
			    sb.append("-- ----------------------------------------- \n ");
			    sb.append("DROP TABLE IF EXISTS `dh_order_resource_products_detail`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_order_resource_products_detail` (");
			    sb.append("\n");
			    sb.append(" `order_resource_products_detail_id` varchar(32) NOT NULL," + "\n"
			    		 + " `order_id` varchar(32) NOT NULL," + "\n"
			    		  + " `order_product_id` varchar(32) NOT NULL," + "\n"
			    		  + " `product_id` varchar(32) NOT NULL," + "\n"
			    		  + " `product_name` varchar(100) DEFAULT NULL," + "\n"
			    		  + " `product_type` int(11) NOT NULL DEFAULT '0' COMMENT '0：资源分类  1:资源'," + "\n"
			    		  + " `res_type_id` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `res_table` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `res_type_name` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `publishdate` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `order_type` int(11) DEFAULT NULL," + "\n"
			    		  + " `publishyear` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `publishmonth` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `institutions_id` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `up_institutions_id` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `res_category_id` varchar(32) NOT NULL," + "\n"
			    		  + " `res_category_name` varchar(200) NOT NULL," + "\n"
			    		  + " `up_res_category_id` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `alias` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `product_abbreviation` varchar(10) DEFAULT NULL," + "\n"
			    		  + " `create_time` varchar(20) DEFAULT NULL," + "\n"
			    		  + " `product_price` varchar(20) DEFAULT NULL," + "\n"
			    		  + " `unit_count` int(11) DEFAULT '0'," + "\n"
					+ " PRIMARY KEY (`order_resource_products_detail_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    
			    //update
			    if (null != orderResourceProductsDetailList && orderResourceProductsDetailList.size() > 0) {
					for (OrderResourceProductsDetail orderResourceProductsDetail : orderResourceProductsDetailList) {
						sb.append("INSERT INTO `dh_order_resource_products_detail` VALUES (");
					    sb.append(
					 	"'"+stringIsNull(orderResourceProductsDetail.getOrderResourceProductsDetailId())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getOrderId())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getOrderProductId())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getProductId())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getProductName())+"'"+
					    ", "+orderResourceProductsDetail.getProductType()+
					    ", '"+stringIsNull(orderResourceProductsDetail.getResTypeId())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getResTable())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getResTypeName())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getPublishdate())+"'"+
					    ", "+orderResourceProductsDetail.getOrderType()+
					    ", '"+stringIsNull(orderResourceProductsDetail.getPublishyear())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getPublishmonth())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getInstitutionsId())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getUpInstitutionsId())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getResCategoryId())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getResCategoryName())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getUpResCategoryId())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getAlias())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getProductAbbreviation())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getCreateTime())+"'"+
					    ", '"+stringIsNull(orderResourceProductsDetail.getProductPrice())+"'"+
						", "+orderResourceProductsDetail.getUnitCount()+");");
					    sb.append("\n");
					}
					sb.append("\n \n \n");
				}
			    
			    
			    
			    //13、订单目录价格表离线数据包？？？？：全量升级
			    List<OrderResoursePrice> orderResoursePricesList = exportInstitutionListByIdVo.getOrderResoursePriceList();
			    sb.append("-- ----------------------------------------- \n ");
			    sb.append("-- dh_order_resourse_price ----------------- \n ");
			    sb.append("-- ----------------------------------------- \n ");
			    sb.append("DROP TABLE IF EXISTS `dh_order_resourse_price`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_order_resourse_price` (");
			    sb.append("\n");
			    sb.append(" `order_price_id` varchar(32) NOT NULL," + "\n"
		    		  + " `order_id` varchar(32) NOT NULL," + "\n"
		    		  + " `order_product_id` varchar(32) NOT NULL," + "\n"
		    		  + " `res_category_id` varchar(32) NOT NULL," + "\n"
		    		  + " `order_type` int(1) DEFAULT '0'," + "\n"
		    		  + " `product_type` int(1) DEFAULT '0'," + "\n"
		    		  + " `totalPrice` varchar(100) NOT NULL," + "\n"
					  + " PRIMARY KEY (`order_price_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    //update
			    if (null != orderResoursePricesList && orderResoursePricesList.size() > 0) {
					for (OrderResoursePrice orderResoursePrice : orderResoursePricesList) {
						sb.append("INSERT INTO `dh_order_resourse_price` VALUES (");
					    sb.append(
					 	"'"+stringIsNull(orderResoursePrice.getOrderPriceId())+"'"+
					    ", '"+stringIsNull(orderResoursePrice.getOrderId())+"'"+
					    ", '"+stringIsNull(orderResoursePrice.getOrderProductId())+"'"+
					    ", '"+stringIsNull(orderResoursePrice.getResCategoryId())+"'"+
					    ", "+orderResoursePrice.getOrderType()+
					    ", "+orderResoursePrice.getProductType()+
						", "+stringIsNull(orderResoursePrice.getTotalprice())+");");
					    sb.append("\n");
					}
					 sb.append("\n \n \n");
				}
			    
			    //13、订单审核日志离线数据包？？？？：全量升级
			    List<AuditLogs> auditLogsList = exportInstitutionListByIdVo.getAuditLogsList();
			    sb.append("-- ----------------------------------------- \n ");
			    sb.append("-- dh_audit_logs --------------------------- \n ");
			    sb.append("-- ----------------------------------------- \n ");
			    sb.append("DROP TABLE IF EXISTS `dh_audit_logs`;");
			    sb.append("\n");
			    sb.append("CREATE TABLE `dh_audit_logs` (");
			    sb.append("\n");
			    sb.append(" `product_log_id` varchar(32) NOT NULL," + "\n"
			    		  + " `audit_type` int(11) DEFAULT NULL," + "\n"
			    		  + " `audit_type_id` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `audit_name` varchar(50) DEFAULT NULL," + "\n"
			    		  + " `status` int(11) DEFAULT '0'," + "\n"
			    		  + " `description` varchar(255) DEFAULT NULL," + "\n"
			    		  + " `create_user_id` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `create_date` datetime DEFAULT NULL," + "\n"
			    		  + " `handler` varchar(32) DEFAULT NULL," + "\n"
			    		  + " `last_modify_date` datetime DEFAULT NULL," + "\n"
					  + " PRIMARY KEY (`product_log_id`)");
			    sb.append("\n");
			    sb.append(") ENGINE=InnoDB DEFAULT CHARSET=utf8;");
			    sb.append("\n \n");
			    //update
			    if (null != auditLogsList && auditLogsList.size() > 0) {
					for (AuditLogs auditLogs : auditLogsList) {
						sb.append("INSERT INTO `dh_audit_logs` VALUES (");
					    sb.append(
					 	"'"+stringIsNull(auditLogs.getProductLogId())+"'"+
					    ", "+auditLogs.getAuditType()+
					    ", '"+stringIsNull(auditLogs.getAuditTypeId())+"'"+
					    ", '"+stringIsNull(auditLogs.getAuditName())+"'"+
					    ", "+auditLogs.getStatus()+
					    ", '"+stringIsNull(auditLogs.getDescription())+"'"+
					    ", '"+stringIsNull(auditLogs.getCreateUserId())+"'"+
					    ", "+dateIsNull(DateUtil.formatToString(auditLogs.getCreateDate()))+
					    ", '"+stringIsNull(auditLogs.getHandler())+"'"+
						", "+dateIsNull(DateUtil.formatToString(auditLogs.getLastModifyDate()))+");");
					    sb.append("\n");
					}
					 sb.append("\n \n \n");
				}
			}
//		}
	    
	    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
	    String date = sf.format(new Date());
	    String fileName = date+ "_"+ institutionId+".sql";
	    
	    HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
	    String realPath = request.getServletContext().getRealPath("WEB-INF/SQL/");
//	    System.out.println(realPath);
	    //创建目录
	    CreateFileUtil.createDir(realPath);
	    String filePath = CreateFileUtil.createFile(realPath+ File.separator +fileName, sb.toString());
	    
	   
         // 上传xls文件转 MultipartFile
        ResourceBundle resource = ResourceBundle.getBundle("application");
        String url = resource.getString("uploadFile");
        String target = "institution/" + date;
        Map resultMap = null;
        try{
	        MultipartFile multi = new MockMultipartFile(fileName, new FileInputStream(filePath));
	        String uploadFilePath = ImportClientHttpUtil.HttpImagePost(url, fileName, target, multi, "");
	        resultMap = JsonUtils.fromJson(uploadFilePath, HashMap.class);
        }catch(Exception ex){
        	LogCvt.error("下载机构订单更新包失败," + ex.getMessage());
        }
        String orderExportPath = (String) resultMap.get("filePath");
		return orderExportPath;
	}
	
	public static String stringIsNull(String string){
		String result = null;
		if (null != string) {
			result = string;
		}else{
			result = "";
		}
		return result;
	}
	
	public static String dateIsNull(String string){
		String result = null;
		if (null != string) {
			result = "'"+string+"'";
		}else{
			result = null;
		}
		return result;
	}
	
	public static String stringReplace(String string){
		String result = null;
		if (StringUtils.isNotBlank( string )) {
			if(string.indexOf("'")>-1){
				string = string.replace( "\'", "\\'" );
			}
			if(string.indexOf(  "/'" )>-1){
				string = string.replace( "/'", "/\\'" ) ;
			}
			if(string.indexOf( "\"" )>-1){
				string = string.replace( "\"", "\\\"" ) ;
			}	
			
			result = string;
			
		}else{
			result = "";
		}
		return result;
	}

//	public static void main(String[] args) throws ParseException {
//		StringBuffer sb = new StringBuffer();
//		sb.append("INSERT INTO `dh_user_institution`("
//    			+ "`user_institution_id`,`institution_id`,`user_id`,`relation`)");
//    	sb.append("SELECT ");
//    	sb.append(
//	    		"'0000'"+
//				", '0000'"+
//	    	    ", '0000'"+
//	    	    ", '000'");    			 	
//    	sb.append(" FROM DUAL WHERE NOT EXISTS(");
//    	sb.append("SELECT `user_institution_id` FROM `dh_user_institution` WHERE `user_institution_id` = "+"'0000');");
//    	System.out.println(sb.toString());
//System.out.println(DateUtil.parseFormatToDate(DateUtil.getCurTotalDate()));
//	}
}
